package com.hdax.dm.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.dto.ScheduleDto;
import com.hdax.dm.entity.scheduler.DmSchedulerSeat;
import com.hdax.dm.entity.scheduler.DmSchedulerSeatPrice;
import com.hdax.dm.mappers.PriceMapper;
import com.hdax.dm.mappers.SeatMapper;
import com.hdax.dm.mapstrucs.ScheduleDtoMapper;
import com.hdax.dm.service.PriceService;
import com.hdax.dm.service.SeatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;


@Service
public class PriceSImpl extends ServiceImpl<PriceMapper, DmSchedulerSeatPrice> implements PriceService {

    @Autowired
    private ScheduleDtoMapper scheduleDtoMapper;

    @Override
    public List<ScheduleDto.SeatPriceDto> seatPrice(Long scheduleId) {
        QueryWrapper<DmSchedulerSeatPrice> wrapper=new QueryWrapper<>();
        wrapper.eq("scheduleId",scheduleId);
        List<DmSchedulerSeatPrice> price= list(wrapper);
        List<ScheduleDto.SeatPriceDto> scheduleDto= scheduleDtoMapper.priceToTargets(price);
        for (int i = 0; i < price.size(); i++) {
            if (price.get(i).getAreaLevel()==1){
                scheduleDto.get(i).setAreaLevelName("A");
            }else  if (price.get(i).getAreaLevel()==2){
                scheduleDto.get(i).setAreaLevelName("B");
            }else if (price.get(i).getAreaLevel()==3){
                scheduleDto.get(i).setAreaLevelName("C");
            }

        }
        return scheduleDto;
    }

    @Override
    public DmSchedulerSeatPrice price(Long scheduleId, Long areaLevel) {
        QueryWrapper<DmSchedulerSeatPrice> wrapper=new QueryWrapper<>();
        wrapper.eq("scheduleId",scheduleId);
        wrapper.eq("areaLevel",areaLevel);
        return getOne(wrapper);
    }
}
